{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7813e268",
   "metadata": {},
   "outputs": [],
   "source": [
    "import tushare as ts\n",
    "ts.set_token('a655fc3834af5844dbaf2de203e28796063136209537509777b8f5f1')\n",
    "api = ts.pro_api()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a4e34de9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>trade_date</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>change</th>\n",
       "      <th>pct_chg</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20180718</td>\n",
       "      <td>8.75</td>\n",
       "      <td>8.85</td>\n",
       "      <td>8.69</td>\n",
       "      <td>8.70</td>\n",
       "      <td>8.72</td>\n",
       "      <td>-0.02</td>\n",
       "      <td>-0.23</td>\n",
       "      <td>525152.77</td>\n",
       "      <td>460697.377</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20180717</td>\n",
       "      <td>8.74</td>\n",
       "      <td>8.75</td>\n",
       "      <td>8.66</td>\n",
       "      <td>8.72</td>\n",
       "      <td>8.73</td>\n",
       "      <td>-0.01</td>\n",
       "      <td>-0.11</td>\n",
       "      <td>375356.33</td>\n",
       "      <td>326396.994</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20180716</td>\n",
       "      <td>8.85</td>\n",
       "      <td>8.90</td>\n",
       "      <td>8.69</td>\n",
       "      <td>8.73</td>\n",
       "      <td>8.88</td>\n",
       "      <td>-0.15</td>\n",
       "      <td>-1.69</td>\n",
       "      <td>689845.58</td>\n",
       "      <td>603427.713</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20180713</td>\n",
       "      <td>8.92</td>\n",
       "      <td>8.94</td>\n",
       "      <td>8.82</td>\n",
       "      <td>8.88</td>\n",
       "      <td>8.88</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>603378.21</td>\n",
       "      <td>535401.175</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20180712</td>\n",
       "      <td>8.60</td>\n",
       "      <td>8.97</td>\n",
       "      <td>8.58</td>\n",
       "      <td>8.88</td>\n",
       "      <td>8.64</td>\n",
       "      <td>0.24</td>\n",
       "      <td>2.78</td>\n",
       "      <td>1140492.31</td>\n",
       "      <td>1008658.828</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20180711</td>\n",
       "      <td>8.76</td>\n",
       "      <td>8.83</td>\n",
       "      <td>8.68</td>\n",
       "      <td>8.78</td>\n",
       "      <td>8.98</td>\n",
       "      <td>-0.20</td>\n",
       "      <td>-2.23</td>\n",
       "      <td>851296.70</td>\n",
       "      <td>744765.824</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20180710</td>\n",
       "      <td>9.02</td>\n",
       "      <td>9.02</td>\n",
       "      <td>8.89</td>\n",
       "      <td>8.98</td>\n",
       "      <td>9.03</td>\n",
       "      <td>-0.05</td>\n",
       "      <td>-0.55</td>\n",
       "      <td>896862.02</td>\n",
       "      <td>803038.965</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20180709</td>\n",
       "      <td>8.69</td>\n",
       "      <td>9.03</td>\n",
       "      <td>8.68</td>\n",
       "      <td>9.03</td>\n",
       "      <td>8.66</td>\n",
       "      <td>0.37</td>\n",
       "      <td>4.27</td>\n",
       "      <td>1409954.60</td>\n",
       "      <td>1255007.609</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20180706</td>\n",
       "      <td>8.61</td>\n",
       "      <td>8.78</td>\n",
       "      <td>8.45</td>\n",
       "      <td>8.66</td>\n",
       "      <td>8.60</td>\n",
       "      <td>0.06</td>\n",
       "      <td>0.70</td>\n",
       "      <td>988282.69</td>\n",
       "      <td>852071.526</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20180705</td>\n",
       "      <td>8.62</td>\n",
       "      <td>8.73</td>\n",
       "      <td>8.55</td>\n",
       "      <td>8.60</td>\n",
       "      <td>8.61</td>\n",
       "      <td>-0.01</td>\n",
       "      <td>-0.12</td>\n",
       "      <td>835768.77</td>\n",
       "      <td>722169.579</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20180704</td>\n",
       "      <td>8.63</td>\n",
       "      <td>8.75</td>\n",
       "      <td>8.61</td>\n",
       "      <td>8.61</td>\n",
       "      <td>8.67</td>\n",
       "      <td>-0.06</td>\n",
       "      <td>-0.69</td>\n",
       "      <td>711153.37</td>\n",
       "      <td>617278.559</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20180703</td>\n",
       "      <td>8.69</td>\n",
       "      <td>8.70</td>\n",
       "      <td>8.45</td>\n",
       "      <td>8.67</td>\n",
       "      <td>8.61</td>\n",
       "      <td>0.06</td>\n",
       "      <td>0.70</td>\n",
       "      <td>1274838.57</td>\n",
       "      <td>1096657.033</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>20180702</td>\n",
       "      <td>9.05</td>\n",
       "      <td>9.05</td>\n",
       "      <td>8.55</td>\n",
       "      <td>8.61</td>\n",
       "      <td>9.09</td>\n",
       "      <td>-0.48</td>\n",
       "      <td>-5.28</td>\n",
       "      <td>1315520.13</td>\n",
       "      <td>1158545.868</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      ts_code trade_date  open  high   low  close  pre_close  change  pct_chg  \\\n",
       "0   000001.SZ   20180718  8.75  8.85  8.69   8.70       8.72   -0.02    -0.23   \n",
       "1   000001.SZ   20180717  8.74  8.75  8.66   8.72       8.73   -0.01    -0.11   \n",
       "2   000001.SZ   20180716  8.85  8.90  8.69   8.73       8.88   -0.15    -1.69   \n",
       "3   000001.SZ   20180713  8.92  8.94  8.82   8.88       8.88    0.00     0.00   \n",
       "4   000001.SZ   20180712  8.60  8.97  8.58   8.88       8.64    0.24     2.78   \n",
       "5   000001.SZ   20180711  8.76  8.83  8.68   8.78       8.98   -0.20    -2.23   \n",
       "6   000001.SZ   20180710  9.02  9.02  8.89   8.98       9.03   -0.05    -0.55   \n",
       "7   000001.SZ   20180709  8.69  9.03  8.68   9.03       8.66    0.37     4.27   \n",
       "8   000001.SZ   20180706  8.61  8.78  8.45   8.66       8.60    0.06     0.70   \n",
       "9   000001.SZ   20180705  8.62  8.73  8.55   8.60       8.61   -0.01    -0.12   \n",
       "10  000001.SZ   20180704  8.63  8.75  8.61   8.61       8.67   -0.06    -0.69   \n",
       "11  000001.SZ   20180703  8.69  8.70  8.45   8.67       8.61    0.06     0.70   \n",
       "12  000001.SZ   20180702  9.05  9.05  8.55   8.61       9.09   -0.48    -5.28   \n",
       "\n",
       "           vol       amount  \n",
       "0    525152.77   460697.377  \n",
       "1    375356.33   326396.994  \n",
       "2    689845.58   603427.713  \n",
       "3    603378.21   535401.175  \n",
       "4   1140492.31  1008658.828  \n",
       "5    851296.70   744765.824  \n",
       "6    896862.02   803038.965  \n",
       "7   1409954.60  1255007.609  \n",
       "8    988282.69   852071.526  \n",
       "9    835768.77   722169.579  \n",
       "10   711153.37   617278.559  \n",
       "11  1274838.57  1096657.033  \n",
       "12  1315520.13  1158545.868  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#获取日线数据\n",
    "df = api.daily(ts_code='000001.SZ', start_date='20180701', end_date='20180718')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2e61df6d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
